package top.chenyp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;
import top.chenyp.config.Constants;
import top.chenyp.javabean.QQUrl;
import top.chenyp.javabean.QQUserInfo;
import top.chenyp.utils.URLEncodeUtil;

import javax.servlet.http.HttpSession;
import javax.websocket.Session;
import java.io.IOException;
import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private Constants constants;



    @GetMapping("/getQQUrl")
    public QQUrl getQQUrl(){

        // 拼接url
        StringBuilder url = new StringBuilder();
        url.append("https://graph.qq.com/oauth2.0/authorize?");
        url.append("response_type=code");
        url.append("&client_id=" + constants.getQqAppId());
        // 回调地址 ,回调地址要进行Encode转码
        String redirect_uri = constants.getQqRedirectUrl();
        // 转码
        url.append("&redirect_uri=" + URLEncodeUtil.getURLEncoderString(redirect_uri));
        url.append("&state=ok");
        // HttpClientUtils.get(url.toString(), "UTF-8");

        QQUrl qqUrl=new QQUrl();
        qqUrl.setUrl(url.toString());
        return qqUrl;
    }

    @GetMapping("/hello1")
    public void hello1() throws IOException {

    }



    @GetMapping("/hello2")
    public QQUrl hello2(HttpSession session) throws IOException {
        System.out.println((QQUrl) session.getAttribute("url"));
        return (QQUrl) session.getAttribute("url");
    }
}
